//
//  NetworkData.m
//  QuickDoctor
//
//  Created by Eric on 2016-12-20.
//  Copyright © 2016 Eric. All rights reserved.
//

#import "NetworkData.h"
#import "NetworkTool.h"
#import "NetworkDefine.h"

@implementation NetworkData


+ (instancetype)sharedNetworkData {
    
    static id instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [self new];
    });
    return instance;
    
}


- (void)getLoginDataWithCompleteBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/carelinkQuickLogin.json.php";
    NSDictionary *parmas = @{@"login_token":@"985c96ce43bb5ef69de3e1ad8afaa83f"};
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}


- (void)getCycleDataWithCompleteBlock:(CompletedBlock)completeBlock {
    
    NSString *urlString = @"http://iosapi.itcast.cn/banners.json.php";
    NSDictionary *parmas = @{
                             @"login_token":@"985c96ce43bb5ef69de3e1ad8afaa83f",
                             @"page_size":@10,
                             @"page":@1
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}


- (void)getCIListDataWith:(NSNumber *)CINumber pageNumber:(NSNumber *)pageNumber completeBlock:(CompletedBlock)completeBlock
{
    NSString *urlString = @"http://iosapi.itcast.cn/searchCI3List.json.php";
    NSDictionary *parmas = @{
                             @"page_size":@15,
                             @"page":pageNumber,
                             @"ci1_id":CINumber,
                             @"keyword":@""
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

-(void)getMatchedDoctorCountWithCompleteBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/matchedDoctorCount.json.php";
    NSDictionary *parmas = @{
                             @"ci1_id":@1,
                             @"ci2_id":@3,
                             @"ci3_id":@3,
                             @"diagnosis_type":@0,
                             @"is_confirmed":@1,
                             @"user_id":@1000089,
                             @"has_diagnosis":@2
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

- (void)getComplicationListWithCompleteBlock:(CompletedBlock)completeBlock{
    NSString *urlString = @"http://iosapi.itcast.cn/complicationList.json.php";
    NSDictionary *parmas = @{
                             @"page":@1,
                             @"page_size":@15,
                             @"ci2_id":@3
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}


- (void)getMatchDoctorsWithPageNumber:(NSNumber *)pageNumber completeBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/matchDoctors.json.php";
    NSDictionary *parmas = @{
                             @"ci1_id":@1,
                             @"ci2_id":@3,
                             @"ci3_id":@3,
                             @"diagnosis_type":@0,
                             @"page_size":@15,
                             @"is_confirmed":@1,
                             @"user_id":@1000089,
                             @"page":pageNumber,
                             @"has_diagnosis":@2
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
    
}

- (void)getDoctorInfoWithCompleteBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/getDoctorInfo.json.php";
    NSDictionary *parmas = @{
                             @"user_id":@1000089,
                             @"doctor_id":@300000315
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

- (void)getDoctorReceivingSettingInfoWithCompleteBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/doctorReceivingSetting.json.php";
    NSDictionary *parmas = @{
                             @"doctor_id":@300000315
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

- (void)getDoctorIntroductionWithCompleteBlock:(CompletedBlock)completeBlock {
    
    NSString *urlString = @"http://iosapi.itcast.cn/getIntroduction.json.php";
    NSDictionary *parmas = @{
                             @"doctor_id":@300000315
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

- (void)getDoctorDutiesWithCompleteBlock:(CompletedBlock)completeBlock {
    
    NSString *urlString = @"http://iosapi.itcast.cn/doctorDuties.json.php";
    NSDictionary *parmas = @{
                             @"doctor_id":@300000315
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

-(void)getWeatherInfoWithCity:(NSString *)cityName completeBlock:(CompletedBlock)completeBlock{
    NSString *urlString = kGetWeather_URL(cityName);
    urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [[NetworkTool shareManager] GET_RequestWithUrlString:urlString parmas:nil successBloock:^(id responseObject) {
        
        completeBlock(responseObject,nil);
    
    } failureBlock:^(NSError *error) {
        completeBlock(nil, error);
    }];
}

- (void)addDoctorWithCompleteBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/addDoctor.json.php";
    NSDictionary *parmas = @{
                             @"user_id":@"1000089",
                             @"doctor_id":@300000315
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

- (void)deleteDoctorWithCompleteBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/deleteDoctor.json.php";
    NSDictionary *parmas = @{
                             @"user_id":@"1000089",
                             @"doctor_id":@300000315
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
}

- (void)getAddDoctorsListWithCompleteBlock:(CompletedBlock)completeBlock{
    
    NSString *urlString = @"http://iosapi.itcast.cn/doctorList.json.php";
    NSDictionary *parmas = @{
                             @"user_id":@"1000089",
                             @"page_size":@15,
                             @"page":@1
                             };
    [self loadURL:urlString parmas:parmas completionBlock:completeBlock];
    
}



/*
 * default is POST
 */
- (void)loadURL:(NSString *)urlString parmas:(NSDictionary *)parmas completionBlock:(CompletedBlock)completedBlock
{
    [[NetworkTool shareManager] POST_RequestWithUrlString:urlString parmas:parmas successBloock:^(id responseObject) {
        completedBlock(responseObject, nil);
    } failureBlock:^(NSError *error) {
        completedBlock(nil,error);
    }];
}

@end
